package main

import "fmt"

/*
## 寻找最长不含有重复字符的子串
https://leetcode.com/problems/longest-substring-without-repeating-characters/
- abcabcbb --> abc  3
- bbbbb --> b 1
- pwwkew --> wke 3
*/

func lengthOfLongestSubstring(s string) int {
	lastOccureed := make(map[rune]int)
	start := 0
	maxLength := 0
	for i, ch := range []rune(s) { //用s ch是int32类型

		if lastI, ok := lastOccureed[ch]; ok && lastI >= start {
			start = lastI + 1
		}
		if i-start+1 > maxLength {
			maxLength = i - start + 1
		}
		lastOccureed[ch] = i
	}
	return maxLength
}

func main() {
	fmt.Println(lengthOfLongestSubstring("abcabcsfds"))
	fmt.Println(lengthOfLongestSubstring("地夺爱你的天要地一地"))
}
